﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "AddGong";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}

<h2>工艺库查看</h2>

<div id="">
    <form class="row padtop col-12" action="#" method="post">
        <fieldset class="boun">
            <legend class="len">@Resource.String155</legend>
            <div class="nav">
                <p class="col">
                    @Html.Label(Resource.String224)
                    @Html.TextBox("shen", "", new { @class="input-au"})
                </p>
                <p class="col">
                    @Html.Label(Resource.String225)
                    @Html.TextBox("ming", "", new { @class = "input-au" })
                </p>
                <p class="col">
                    @Html.Label(Resource.String226)
                    <select id="shi" class="input-au" style="width: 180px;margin-top:0">
                        <option value="">无</option>
                        @foreach (var item in ViewBag.S_tea as List<Steelmaking>)
                        {
                            <option value="@item.ST_ID">@item.ST_fne</option>
                        }
                    </select>
                </p>
                <p class="col-3">
                    <input type="button" value="@Resource.String155" name="cha" class=" btn-secondary btn-sm" />
                </p>
            </div>

        </fieldset>
    </form>
    <div>
        <input type="button" name="tianjia" value="@Resource.String237" class="btn" />
        @if (MyAuthentication.IsLogin())
        {
            if (MyAuthentication.GetUsers().DE_quan == "管理员")
            {<input type="button" name="Fenlei" value="添加工艺" class="btn" />}
        }

    </div>
    <div style="height:500px;">
        <table class="tab table ">
            <thead class="thead-light">
                <tr style="text-align-last:center;">
                    <th scope="col">@Resource.String227</th>
                    <th scope="col" id="Dan">@Resource.String224</th>
                    <th scope="col">@Resource.String225</th>
                    <th scope="col">@Resource.String228</th>
                    <th scope="col">@Resource.String229</th>
                    <th scope="col">@Resource.String230</th>
                    <th scope="col">@Resource.String231</th>
                    <th scope="col">@Resource.String232</th>
                </tr>
            </thead>
            <tbody class="gun" id="BUtain" style="height:440px;">
            </tbody>
        </table>
        @*@Html.ActionLink("Bom", "BOMView", new { Controller = "Detailed", Action = "BOMView" }, new { @class = "nav=link" })*@
    </div>
</div>
@*添加工艺部分*@
<div class="CenterDiv" style="text-align-last:center; display:none;" id="div1">
    <form>
        <fieldset class="boun">
            <legend class="len1">@Resource.String238</legend>
            <table id="ULen" style="width:70%;margin-left:15%">
                <tr><td>@Resource.String224：</td><td>@Html.TextBox("bian")</td></tr>
                <tr><td>@Resource.String225：</td><td>@Html.TextBox("name")</td></tr>
                <tr>
                    <td>@Resource.String228:</td>
                    <td>
                        <select name="fen">
                            @foreach (var item in ViewBag.S_tea as List<Steelmaking>)
                            {
                                <option>@item.ST_ID .@item.ST_fne</option>
                            }
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>@Resource.String229:</td>
                    <td>
                        <select name="dan">
                            <option>无</option>
                            <option>模</option>
                            <option>/1000张/色</option>
                            <option>平方</option>
                            <option>米</option>
                            <option>KG</option>
                        </select>
                    </td>
                </tr>
                <tr><td>@Resource.String230:</td><td><input type="number" name="price" value="" min="0" /></td></tr>
                <tr><td>@Resource.String231:</td><td>@Html.TextBox("shun")</td></tr>
            </table>
            <input type="button" name="TUIchu" value="@Resource.String235" id="tui1" class="btn" />
            <input type="button" name="Queding" value="@Resource.String236" id="que1" class="btn" />
        </fieldset>
    </form>
</div>
@*添加分类部分*@

<div class="CenterDiv" style="display:none" id="div2">
    <form>
        <fieldset class="boun">
            <legend class="len1">@Resource.String233</legend>
            <table id="ULen">
                <tr><td>@Resource.String234：</td><td><input type="text" name="fenBian" value="" readonly /></td></tr>
                <tr><td>@Resource.String234：</td><td><input type="text" name="fenB" value="" /></td></tr>
            </table>
            <input type="button" name="BTUIchu" value="@Resource.String235" id="tui2" class="btn" />
            <input type="button" name="BQueding" value="@Resource.String236" id="que2" class="btn" />
        </fieldset>
    </form>
</div>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        //页面加载
        $(function () {
            $("#li20").css({ "color": "black", "background-color": "white" })
            $("#ULen input,select").addClass("addinput")
            //点击添加事件--添加工艺
            $('input[name="tianjia"]').click(function () {
                $("#div1").show();
                $("#div2").hide();
            })
            //点击添加事件--添加工艺分类
            $('input[name="Fenlei"]').click(function () {
                $("#div1").hide();
                $("#div2").show();
            })
            //退出事件
            $("#tui1").click(function () {
                $("#div1").hide();
            })
            $("#tui2").click(function () {
                $("#div2").hide();
            })

            randomGeneration();
            //产生随机数
            function randomGeneration() {
                //产生随机数
                var x = 1000000
                var y = 9999999
                var num = parseInt(Math.random() * (x - y + 1) + y)
                var now = new Date($.now());
                var afi = "BAM" + num
                //写入随机申请单号
                $("#bian").val(afi)
                $("#bian").attr("readonly", "readonly")
            }

        })
        $(function () {
            $.ajax({
                url: '/Material/AddGong',
                type: 'POST',
                data: { "stantes": 1 },
                success: function (date) {
                    createRow(date);
                },
                error: function (date) {
                    alert(date);
                }
            })
            function createRow(date) {
                $("#BUtain tr").remove();
                $.each(date, function (i, item) {
                    var $tr = (`
                                                <tr>
                                                    <td></td>
                                                    <td style="display:none">${item.LB_ID}</td>
                                                    <td>${item.LB_bai}</td>
                                                    <td>${item.LB_fne}</td>
                                                    <td>${item.ST_fne}</td>
                                                    <td style="display:none">${item.ST_ID}</td>
                                                    <td>${item.LB_dan}</td>
                                                    <td>${item.LB_jia}</td>
                                                    <td>${item.LB_shun} </td>
                                                    <td><input type="button" name="Xiugai" value="@Resource.String232"/></td>
                                                </tr>
                                                `);
                    $("#BUtain").append($tr);
                })
            }
            //查看
            $('input[name="cha"]').click(function () {
                var shen = $("#shen").val()
                var shi = $("#shi option:selected").val()
                var ming = $("#ming").val()
                $.ajax({
                    url: '/Material/AddGong',
                    type: 'POST',
                    data: { "LB_bai": shen, "LB_fne": ming, "ST_fne": shi, "stantes": 2 },
                    success: function (date) {
                        createRow(date);
                    },
                    error: function (date) {
                        alert("错误 请重试！")
                    }
                })
            })
            ///修改工艺
            $(document).on("click", 'input[name="Xiugai"]', function (ad) {
                var sgfh = $(ad.target).parent().parent().children().first().next().text()
                if (confirm("是否修改该行！")) {
                    window.location.href = "/librays/Edit?UPid=" + sgfh
                }
            })

            //保存添加
            $("#que1").click(function () {
                var shu = $('select[name="fen"] option:selected ').text();
                var id = shu.match(/\d+/g)
                console.log(id)
                var da = {
                    LB_bai: $("#bian").val(),
                    LB_fne: $("#name").val(),
                    ST_ID: id,
                    LB_dan: $('select[name="dan"] option:selected').val(),
                    LB_jia: $('input[name="price"]').val(),
                    LB_shun: $("#shun").val()
                }
                $.ajax({
                    url: '/Material/AddGong',
                    type: 'POST',
                    data: { da, "stantes": 3 },
                    success: function (date) {
                        location.reload(true)
                        createRow(date);
                    },
                    error: function (date) {
                        alert("添加失败！")
                    }
                })
            })
            function createRow(date) {
                $("#BUtain tr").remove();
                $.each(date, function (i, item) {
                    var $tr = (`
                                                    <tr>
                                                        <td></td>
                                        <td style="display:none">${item.LB_ID}</td>
                                        <td>${item.LB_bai}</td>
                                        <td>${item.LB_fne}</td>
                                        <td>${item.ST_fne}</td>
                                        <td style="display:none">${item.ST_ID}</td>
                                        <td>${item.LB_dan}</td>
                                        <td>${item.LB_jia}</td>
                                        <td>${item.LB_shun} </td>
                                        <td><input type="button" name="Xiugai" value="@Resource.String232" /></td>
                                                    </tr>
                                                    `);
                    $("#BUtain").append($tr);
                })
                var len = $('#BUtain tr').length;
                for (var i = 0; i < len; i++) {
                    $('#BUtain tr:eq(' + i + ') td:nth-child(1)').text(i + 1);
                }
            }
            //返回工艺分类编号
            $.ajax({
                url: '/Material/AddGong',
                type: 'POST',
                data: { "stantes": 9 },
                success: function (dacd) {
                    var ai = dacd.substring(0, 2)
                    var an = dacd.substring(2, 5)
                    var shun = parseInt(an) + 1
                    var Chushu = ai + shun
                    if (shun < 100) {
                        Chushu = ai + "0" + shun
                    }
                    $('input[name="fenBian"]').val(Chushu)
                },
                error: function () {
                    alert("系统出错！")
                }
            })
            $("#que2").click(function () {
                var Fenname = $('input[name="fenB"]').val();
                var Fenbian = $('input[name="fenBian"]').val();
                console.log(Fenname)
                console.log(Fenbian)
                $.ajax({
                    url: '/Material/AddGong',
                    type: 'POST',
                    data: { "FenL": Fenname, "FenBian": Fenbian, "stantes": 4 },
                    success: function (date) {
                        alert(date)
                    },
                    error: function (date) {
                        alert("添加失败！")
                    }
                })
            })
        })
    </script>
}

